package com.github.byakkili.bim.protocol.json2protobuf.ws;

import com.github.byakkili.bim.core.handler.command.CommandHandler;
import com.github.byakkili.bim.core.protocol.BaseWsProtocol;
import io.netty.channel.Channel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler;
import io.netty.handler.stream.ChunkedWriteHandler;

/**
 * +--------+--------+
 * |  命令  |  JSON  |
 * +--------+--------+
 * |  数字  | 字符串  |
 * +--------+--------+
 *
 * @author Guannian Li
 */
public class WsJson2protoBufProtocol extends BaseWsProtocol {
    @Override
    public String name() {
        return "WS-JsonToProtoBuf";
    }

    @Override
    public void addPipeline(Channel ch) {
        ch.pipeline()
                // .addLast("ContentDecompressor", new HttpContentDecompressor(false))
                .addLast("HttpCodec", new HttpServerCodec())
                .addLast("ChunkedWrite", new ChunkedWriteHandler())
                .addLast("HttpObjectAggregator", new HttpObjectAggregator(1024))
                .addLast("WebSocketServerProtocol", new WebSocketServerProtocolHandler("/ws", true))
                .addLast("WsJson2protoBuf", WsJson2protoBufCodec.INSTANCE)
                .addLast("CommandHandler", CommandHandler.INSTANCE);
    }
}

